package com.guguskins.back.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guguskins.back.entity.GuDiscount;
import com.guguskins.back.entity.vo.ResultVo;
import com.guguskins.back.service.GuDiscountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 折扣表 前端控制器
 * </p>
 *
 * @author mybatis-plus
 * @since 2021-07-14
 */
@RestController
@RequestMapping("/Discount")
public class GuDiscountController {
    @Autowired
    private GuDiscountService discountService;

    @PostMapping("/back/insert")
    public ResultVo backInsert(@RequestBody @Validated GuDiscount discount) {

        discountService.save(discount);
        return ResultVo.success("添加成功");
    }

    @PostMapping("/back/update")
    public ResultVo backUpdate(@RequestBody GuDiscount discount) {
        discountService.updateById(discount);
        return ResultVo.success("修改成功");
    }

    @GetMapping("list")
    public ResultVo list() {
        return ResultVo.success(discountService.list(), "查找成功");
    }

    @GetMapping("/back/list")
    public ResultVo backList() {
        return ResultVo.success(discountService.list(), "查找成功");
    }
    @GetMapping("/back/Delete")
    public ResultVo backDelete(@RequestParam(value = "DcId",required = false) Integer dcId
    ){
        GuDiscount discount=new GuDiscount();
        discount.setDcId(dcId);
        discount.setDcEnable(false);
        discountService.updateById(discount);
        return ResultVo.success("删除成功");
    }
    @GetMapping("/back/findById")
    public ResultVo backFindById(@RequestParam(value = "dcId",required = false) Integer dcId
    ){
        GuDiscount byId = discountService.getById(dcId);

        return ResultVo.success(byId,"查找成功");
    }
}
